<template>
  <div class="tab-sel">
    <div class="tabs-wrapper" ref="tabsWrapper">
      <div class="tabs">
        <div
          class="tabs-item"
          @click="tabCurTab(item, index)"
          :class="{activeTab: activeTabIndex === index}"
          v-for="(item, index) in tabs"
          :key="index + 'k'"
        >
          {{ item.name }}
        </div>
      </div>
    </div>
    <div class="info-wrapper" ref="infoWrapper">
      <div class="info-list">
        <div
          class="list-item"
          @click="tabCurInfo(item, index)"
          :class="{activeInfo: activeInfoIndex === index}"
          v-for="(item, index) in info"
          :key="index + 'x'"
        >
          <p class="header">{{ item.title }}</p>
          <p class="text">{{ item.text }}</p>
        </div>
        
      </div>
    </div>
  </div>
</template>
<script>
import BetterScroll from '@better-scroll/core'
export default {
  name: 'tabSel',
  props: {
    tabs: {
      type: Array,
      default: () => []
    },
    info: {
      type: Array,
      default: () => []
    }
  },
  created() {
    console.log(this.info)
  },
  mounted() {
    this.initBS()
  },
  beforeDestroy() {
    this.scrollTabs.destroy()
    this.scrollInfo.destroy()
  },
  data() {
    return {
      activeInfoIndex: 0,
      activeTabIndex: 0
    }
  },
  methods: {
    initBS() {
      this.$nextTick(() => {
        this.scrollTabs = new BetterScroll(this.$refs.tabsWrapper, {
          scrollX: true
        })
        console.log(this.scroll)
        this.scrollInfo = new BetterScroll(this.$refs.infoWrapper, {
          scrollY: true
        })
      })
    },
    tabCurInfo(item, index) {
      this.activeInfoIndex = index
    },
    tabCurTab(item, index) {
      this.activeTabIndex = index
      this.activeInfoIndex = 0
      this.$emit('seled',index)
    }
  }
}
</script>
<style lang="less">
.tab-sel {
  width: 100%;
  height: 100%;
  font-family: PingFangSC-Medium;
  position: relative;
  .tabs-wrapper {
    width: 100%;
    height: 40px;
    background: #fff;
    // overflow-x: auto;
    // -webkit-overflow-scrolling: touch;
    // padding-bottom: 10px;
    // margin-bottom: -10px;
    overflow: hidden;
    white-space: nowrap;
    border-bottom: 2px solid #4D84FF;

    .tabs {
      display: inline-block;
      .tabs-item {
        display: inline-block;
        padding: 0 10px;
        height: 40px;
        margin-right: 8px;
        background: #ececec;
        border-radius: 3px 3px 0 0;
        font-size: 18px;
        color: #333;
        text-align: center;
        line-height: 40px;
        padding: 0 19px;
        &:hover {
          cursor: pointer;
        }
        &:last-child {
          margin-right: 0;
        }
      }
      .activeTab {
        background: #4d84ff;
        color: #fff;
      }
    }
  }
  .info-wrapper {
    height: 100%;
    overflow-y: auto;
    position: relative;
    border: 1px solid #F3F6FA;
    background: #f3f6fa;
  }
  .info-list {
    background: #f3f6fa;
    width: 100%;
    max-height: 350px;
    padding-top: 10px;
    .list-item {
      box-sizing: border-box;
      padding: 12px 56px;
      background: #fff;
      margin-top: 10px;
      border-left: 3px solid transparent;
      &:hover {
        cursor: pointer;
      }
      .header {
        font-size: 18px;
        color: #333;
      }
      .text {
        font-size: 16px;
        color: #666;
        font-family: 'Serif'
      }
    }
    .list-item:first-child {
      margin: 0;
    }
    .activeInfo {
      border-left: 3px solid #4d84ff;
      .header {
        color: #4d84ff;
      }
      .text {
        color: #85aafd;
      }
    }
  }
}
</style>
